package com.cy.springboot04notice.web.controller;

import com.cy.springboot04notice.pojo.SysNotice;
import com.cy.springboot04notice.service.SysNoticeService;
import com.cy.springboot04notice.web.pojo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/* * restful风格url，对于notice模块而言
         * 查询操作： @GetMaping     /notice/
        * 添加操作： @PostMapping   /notice/
        * 修改操作:  @PutMapping    /notice/
        * 删除操作:  @DeleteMapping /notice/{id}
        * 基于id查找 @GetMapping    /notice/{id}*/
@RestController
@RequestMapping("/notice")
public class SysNoticeController {
    @Autowired
    private SysNoticeService sysNoticeService;

//    @RequestMapping(value = "/doFindNotices",method = RequestMethod.GET)
    @GetMapping
    public JsonResult doFindNotices(SysNotice notice){
        List<SysNotice> notices = sysNoticeService.findNotices(notice);
        return new JsonResult(notices);
    }

//    @RequestMapping(value = "/dosaveNotice",method = RequestMethod.POST)
    @PostMapping
    public JsonResult dosaveNotice(@RequestBody SysNotice sysNotice){
        sysNoticeService.saveNotice(sysNotice);
        System.out.println(sysNotice);
        return new JsonResult("save ok");
    }

//    @RequestMapping(value = "/dodeleteById/{ids}",method = RequestMethod.DELETE)
    @DeleteMapping("/{ids}")
    public JsonResult dodeleteById(@PathVariable(name = "ids") Integer...idss){
        int i = sysNoticeService.deleteById(idss);
        return new JsonResult("delete ok");
    }

//    @RequestMapping("/dofindById")
    @GetMapping("/{id}")
    public JsonResult dofindById(@PathVariable(name = "id") Integer id){
        SysNotice byId = sysNoticeService.findById(id);
        System.out.println(byId);
        return new JsonResult(byId);
    }

//    @RequestMapping(value = "doupdateNotice",method = RequestMethod.PUT)
    @PutMapping
    public JsonResult doupdateNotice(@RequestBody SysNotice sysNotice){
        sysNoticeService.updateNotice(sysNotice);
        return new JsonResult("update ok");
    }

}
